package com.lm.itextpdf.example;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

import com.itextpdf.kernel.events.PdfDocumentEvent;
import com.lm.itextpdf.handler.HeaderFooterHandler;

public class HeaderFooterExample {
    public static void main(String[] args) throws Exception {
        String dest = "header_footer_example.pdf";

        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document document = new Document(pdfDoc);

        pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, new HeaderFooterHandler());

        for (int i = 0; i < 5; i++) {
            document.add(new Paragraph("Page content for page " + (i + 1)));
            document.add(new Paragraph("\n\n\n"));
        }

        document.close();
        System.out.println("PDF with header and footer created at: " + dest);
    }
}
